const fp = require("lodash/fp");
const { Maybe, Container } = require("./support");

// TODO: 练习1
let maybe = Maybe.of([5, 6, 1]) // 函子
let add = fp.curry(fp.add) // 柯里化
let add1 = add(1) // 每项加1
let ex1 = val => fp.map(add1, val)
console.log( maybe.map(ex1) )

// TODO: 练习2
let xs = Container.of(['do', 'ray', 'me', 'fa', 'so', 'la', 'ti', 'do'])
let ex2 = fp.first
console.log( xs.map(ex2) )

// TODO: 练习3
let safeProp = fp.curry(function (x, o) {
	return Maybe.of(o[x])
})
let user = { id: 2, name: 'Albert'}
let ex3 = obj => {
  return safeProp('name')(obj).map(fp.first)
}
console.log( ex3(user) )

// TODO:练习4
let ex4 = v => Maybe.of(v).map(parseInt)

console.log(ex4(1));
console.log(ex4([1,2]));
console.log(ex4('2.234'));